package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.anno.Logs;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/9 10:06
 */
@Slf4j
@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @Logs("根据渠道查询活动")
    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type) {
        return Result.success(activityService.getByChannel(type));
    }

    @Logs("更新活动")
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }

    @Logs("根据ID查询活动")
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        return Result.success(activityService.getById(id));
    }

    @Logs("根据ID删除活动")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }

    @Logs("添加活动")
    @PostMapping
    public Result add(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }

    @GetMapping
    public Result page(ActivityDTO activityDTO) {
        return Result.success(activityService.page(activityDTO));
    }
}
